<!DOCTYPE html>
<html lang="en">

<head>
  <meta charset="UTF-8">
  <meta http-equiv="X-UA-Compatible" content="IE=edge">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <title>Document</title>
</head>

<body>
  <button id="sendBtn">点我发送请求</button>
  <input type="text" list="testlist">
  <progress value="70" max="100">70%</progress>
  <datalist id="testlist">
    <option>你好1</option>
    <option>你好2</option>
    <option>你好3</option>
  </datalist>
  <script src="https://cdn.bootcdn.net/ajax/libs/qs/6.11.2/qs.min.js"></script>
  <script>
    let btn = document.getElementById("sendBtn")
    let qs = Qs
    let xhr = new XMLHttpRequest()
    let baseUrl = "http://127.0.0.1:7001"
    let myAjax = {
      get: function (params, url) {
        return new Promise((resolve, reject) => {

          xhr.open('get', baseUrl + url + '?' + qs.stringify(params))
          xhr.setRequestHeader('Content-Type', 'application/json;charset=utf-8')
          xhr.send()
          xhr.onreadystatechange = function () {
            if (xhr.readyState != 4) return;
            if (xhr.readyState == 4 && xhr.status == 200) {
              let res = xhr.responseText
              // resolve(resData)
              resolve(JSON.parse(res))
            } else {
              console.log("失败了");
              reject("请求失败")
            }

          }
        })


      }
    }
    btn.addEventListener('click', function () {
      let params = {
        name: '皮'
      }
      myAjax.get(params, '/getUserInfo').then(res => {
        console.log(res.data, "请求的结果是");
      })

    })
  </script>

</body>

</html>